package com.example.demo.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentController {
    @RequestMapping("/user")
    @ResponseBody
    public StudentClass user() {
        StudentClass user = new StudentClass();
        user.setID(20666102);
        user.setName("张三");
        user.setspeciality("会计");
        return user;
    }

    @RequestMapping("/information")
    @ResponseBody
    public String saveUser(StudentClass u) {
        return "学号：" + u.getID() + ",  名字：" + u.getName()+" , 专业："+u.getspeciality();}

    @RequestMapping("/html")
    public String html(){
        return "index.html";
    }

    @ModelAttribute
    public void parseUser(@RequestParam(name = "ID", defaultValue = "213411112") Integer ID
            , @RequestParam(name = "name", defaultValue = "大名")  String name,
              @RequestParam(name = "speciality", defaultValue = "动物饲养")  String speciality,StudentClass user) {
        user.setID(2021036641);
        user.setName("小明");
        user.setspeciality("大数据技术");
    }

}